package xworker.javafx.stage;

import javafx.stage.PopupWindow;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;

public class PopupWindowActions {
    static{
        PropertyFactory.regist(PopupWindow.class, "autoFixProperty", o -> {
            PopupWindow obj = (PopupWindow) o;
            return obj.autoFixProperty();
        });
        PropertyFactory.regist(PopupWindow.class, "autoHideProperty", o -> {
            PopupWindow obj = (PopupWindow) o;
            return obj.autoHideProperty();
        });
        PropertyFactory.regist(PopupWindow.class, "onAutoHideProperty", o -> {
            PopupWindow obj = (PopupWindow) o;
            return obj.onAutoHideProperty();
        });
        PropertyFactory.regist(PopupWindow.class, "consumeAutoHidingEventsProperty", o -> {
            PopupWindow obj = (PopupWindow) o;
            return obj.consumeAutoHidingEventsProperty();
        });
        PropertyFactory.regist(PopupWindow.class, "anchorLocationProperty", o -> {
            PopupWindow obj = (PopupWindow) o;
            return obj.anchorLocationProperty();
        });
        PropertyFactory.regist(PopupWindow.class, "hideOnEscapeProperty", o -> {
            PopupWindow obj = (PopupWindow) o;
            return obj.hideOnEscapeProperty();
        });
    }

    public static void init(PopupWindow node, Thing thing, ActionContext actionContext){
        WindowActions.init(thing, node, actionContext);

        if(thing.valueExists("anchorLocation")){
            node.setAnchorLocation(PopupWindow.AnchorLocation.valueOf(thing.getString("anchorLocation")));
        }
        if(thing.valueExists("autoFix")){
            node.setAutoFix(thing.getBoolean("autoFix"));
        }
        if(thing.valueExists("autoHide")){
            node.setAutoHide(thing.getBoolean("autoHide"));
        }
        if(thing.valueExists("consumeAutoHidingEvents")){
            node.setConsumeAutoHidingEvents(thing.getBoolean("consumeAutoHidingEvents"));
        }
        if(thing.valueExists("hideOnEscape")){
            node.setHideOnEscape(thing.getBoolean("hideOnEscape"));
        }
    }
}
